/*
 * @(#)XMLSerializationOPS.java 
 * Copyright (c) 2006 DCIVision Ltd All rights reserved.
 * 
 *  This software is the confidential and proprietary information of DCIVision Ltd 
 *  ("Confidential Information"). You * shall not disclose such Confidential
 *   Information and shall use it only in accordance with the terms of the 
 *   license agreement you entered into with DCIVision Ltd.
 */
package com.dcivision.rules.core;

import java.beans.XMLDecoder;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Map;

import org.mandarax.util.xmlser.LogExceptionListener;
import org.mandarax.zkb.XMLSerializationOPS;

/**
 * <p>
 * Class Name: XMLSerializationOPS
 * </p>
 * 
 * @author Greatwall Shao
 * @company DCIVision Limited
 * @creation date 2006-12-7
 */
public class XMLSerializationReadOPS extends XMLSerializationOPS {

  public XMLSerializationReadOPS() {
    super();
  }
/*
 * (non-Javadoc)
 * @see org.mandarax.zkb.XMLSerializationOPS#importObjects(java.io.InputStream)
 */
  public void importObjects(InputStream in) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
    StringWriter writer = new StringWriter();
    PrintWriter printer = new PrintWriter(writer);
    String line = "";
    while ((line = reader.readLine()) != null) {
      printer.println(line);
    }
    InputStream bin = new ByteArrayInputStream(writer.toString().getBytes("utf-8"));
    XMLDecoder decoder = new XMLDecoder(bin);
    decoder.setExceptionListener(new LogExceptionListener());
    reset();
    objectsByUri = (Map) decoder.readObject();
    reverseMap(objectsByUri, urisByObject);
    decoder.close();
    try{
      reader.close();
      printer.close();      
      writer.close();
    }catch(Exception e){
      
    }
  }

}
